package com.zhuo.project.k3.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.k3.domain.ZzMaterial;
import com.zhuo.project.k3.mapper.ZzMaterialMapper;
import com.zhuo.project.k3.service.IZzMaterialService;

/**
 * 物料基础信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-03-18
 */
@Service
public class ZzMaterialServiceImpl implements IZzMaterialService
{
    @Autowired
    private ZzMaterialMapper zzMaterialMapper;

    /**
     * 查询物料基础信息
     * 
     * @param id 物料基础信息ID
     * @return 物料基础信息
     */
    @Override
    public ZzMaterial selectZzMaterialById(Long id)
    {
        return zzMaterialMapper.selectZzMaterialById(id);
    }

    @Override
    public ZzMaterial selectZzMaterialByMaterialId(String materialId) {
        return zzMaterialMapper.selectZzMaterialByMaterialId(materialId);
    }

    /**
     * 查询物料基础信息列表
     * 
     * @param zzMaterial 物料基础信息
     * @return 物料基础信息
     */
    @Override
    public List<ZzMaterial> selectZzMaterialList(ZzMaterial zzMaterial)
    {
        return zzMaterialMapper.selectZzMaterialList(zzMaterial);
    }

    /**
     * 新增物料基础信息
     * 
     * @param zzMaterial 物料基础信息
     * @return 结果
     */
    @Override
    public int insertZzMaterial(ZzMaterial zzMaterial)
    {
        ZzMaterial filter = new ZzMaterial();
        filter.setFnumber(zzMaterial.getFnumber());
        List<ZzMaterial> filterList = zzMaterialMapper.selectZzMaterialList(filter);
        if(null != filterList && filterList.size()>0){
            Long id = filterList.get(0).getId();
            zzMaterial.setId(id);
            zzMaterial.setUpdateTime(new Date());
            zzMaterial.setUpdateBy(SecurityUtils.getUsername());
            return zzMaterialMapper.updateZzMaterial(zzMaterial);
        }
        zzMaterial.setCreateBy(SecurityUtils.getUsername());
        zzMaterial.setCreateTime(new Date());
        return zzMaterialMapper.insertZzMaterial(zzMaterial);
    }

    /**
     * 修改物料基础信息
     * 
     * @param zzMaterial 物料基础信息
     * @return 结果
     */
    @Override
    public int updateZzMaterial(ZzMaterial zzMaterial)
    {
        return zzMaterialMapper.updateZzMaterial(zzMaterial);
    }

    /**
     * 批量删除物料基础信息
     * 
     * @param ids 需要删除的物料基础信息ID
     * @return 结果
     */
    @Override
    public int deleteZzMaterialByIds(Long[] ids)
    {
        return zzMaterialMapper.deleteZzMaterialByIds(ids);
    }

    /**
     * 删除物料基础信息信息
     * 
     * @param id 物料基础信息ID
     * @return 结果
     */
    @Override
    public int deleteZzMaterialById(Long id)
    {
        return zzMaterialMapper.deleteZzMaterialById(id);
    }
}
